package com.xinghou.platform.util;

import com.xinghou.platform.model.main.DrawPrizeBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qingshengzheng on 16/9/9.
 */
public class BigWheelDrawUtil {

    private final static List<DrawPrizeBean> initDrawList = new ArrayList<DrawPrizeBean>() {{
                 add(new DrawPrizeBean(1, 1, 1));
                 add(new DrawPrizeBean(2, 2, 3));
                 add(new DrawPrizeBean(3, 3, 30));
                 add(new DrawPrizeBean(4, 4, 30));
                 add(new DrawPrizeBean(5, 5, 26));
                 add(new DrawPrizeBean(6, 6, 10));
             }};

    public static DrawPrizeBean generateAward() {
                 List<DrawPrizeBean> initData = initDrawList;
                 long result = randomnum(1, 100);
                 int line = 0;
                 int temp = 0;
                 DrawPrizeBean returnobj = null;
                 int index = 0;
                 for (int i = 0; i < initDrawList.size(); i++) {
                         DrawPrizeBean obj2 = initDrawList.get(i);
                         int c = obj2.getRadio();
                         temp = temp + c;
                         line = 100 - temp;
                         if (c != 0) {
                                 if (result > line && result <= (line + c)) {
                                         returnobj = obj2;
                                         break;
                                     }
                             }
                     }
                 return returnobj;
             }

                 // 获取2个值之间的随机数
                 private static long randomnum(int smin, int smax){
                     int range = smax - smin;
                     double rand = Math.random();
                     return (smin + Math.round(rand * range));
             }

}
